package com.koron.css2.clientCenter.impl;


import com.koron.css2.ServerInterface;
import com.koron.css2.clientCenter.bean.CtmInfoBean;
import com.koron.css2.clientCenter.mapper.CtmInfoMapper;
import com.koron.css2.serviceManage.bean.RequestBean;
import com.koron.css2.serviceManage.bean.UserInfoBean;
import com.koron.css2.serviceManage.utils.JsonUtils;
import com.koron.util.Constant;
import com.koron.util.Tools;
import org.apache.commons.lang3.StringUtils;
import org.koron.ebs.mybatis.SessionFactory;
import org.swan.bean.MessageBean;

/**
 * 根据条件查询客户详细信息
 * 
 * @author 甄玉晴
 *
 */
public class ClientInfoQuery implements ServerInterface {

	@Override
	public MessageBean<?> exec(SessionFactory factory, UserInfoBean userInfo, RequestBean req) {
		try {
			MessageBean<CtmInfoBean> info = MessageBean.create(Constant.MESSAGE_INT_SUCCESS, "查询成功", CtmInfoBean.class);
			CtmInfoBean bean = JsonUtils.objectToPojo(req.getData(), CtmInfoBean.class);
			//客户编号不能为空
			if(bean==null||StringUtils.isBlank(bean.getCtmNo())) {
				return MessageBean.create(Constant.ILLEGAL_PARAMETER, "查询失败,缺少查询条件", null);
			}
			CtmInfoMapper mapper = factory.getMapper(CtmInfoMapper.class);
			// 查询列表
			CtmInfoBean ctmInfo = mapper.ClientInfoList(bean,CtmInfoBean.CTM);
			// 获取数据字典信息
			if (StringUtils.isNotBlank(ctmInfo.getCtmType())) {
				ctmInfo.setCtmType(Tools.getDicNameByCodeAndValue(factory, "CTT", ctmInfo.getCtmType()));
			}
			if (StringUtils.isNotBlank(ctmInfo.getCreditLevel())) {
				ctmInfo.setCreditLevel(Tools.getDicNameByCodeAndValue(factory, "CDL", ctmInfo.getCreditLevel()));
			}
			if (StringUtils.isNotBlank(ctmInfo.getCertType())) {
				ctmInfo.setCertType(Tools.getDicNameByCodeAndValue(factory, "IDT", ctmInfo.getCertType()));
			}
			info.setData(ctmInfo);
			return info;
		} catch (Exception e) {
			logger.error("客户信息查询失败" + e.getMessage(), e);
			return MessageBean.create(Constant.MESSAGE_INT_FAIL, "查询失败", null);
		}
	}

}
